home *** CD-ROM | disk | FTP | other *** search
- IDEAL
- DOSSEG
- MODEL SMALL
- STACK 400h
- CODESEG
- p286
- ────────────────────────────────────────────────────────────────────────────
- TimeOut = 364 ;20 seconds (18.2 * 20)
- NormWait = 18 ;1 second
- BuffSize = 2048 ;Size of incoming buffer (in bytes)
-
- ; The following equates are modem configuration settings
- ComInt = 0ch ;COM1/COM3=0Ch, COM2/COM4=0Bh
- ComAddr = 3F8h ;COM1=3F8h, COM2=2F8h, COM3=3E8h, COM4=2E8h
-
- BRDMSB = 0
- BRDLSB = 03h
-
- ;BRDMSB = 0
- ;BRDLSB = 1,843,200/(16*baud rate)
- ;
- ; 60h = 1200
- ; 30h = 2400
- ; 0ch = 9600
- ; 06h = 19200
- ; 03h = 38400
- ; 02h = 57600
- ; 01h = 115200
-
- ; The following equates are for data format settings
- DF_N81 = 00000011b ;8 data bits, 1 stop bit, no parity
- DF_E71 = 00011010b ;7 data bits, 1 stop bit, even parity
-
- OldComInt dd ?
-
- SendCount dw 0000
- CTMax DW 0000
-
- MSG_SetUp db 'Setting up modem information ...',13,10,0
- MSG_NoMem db 'Could not allocate buffer space',13,10,0
- MSG_Exit db 'Press F-12 to exit program',13,10,13,10,0
- MSG_TimeOut db '!',0
-
- BuffSeg DW 0000
- Head DW 0000
- Tail DW 0000
-
- LocalEcho db 0
- ────────────────────────────────────────────────────────────────────────────
- ────────────────────────────────────────────────────────────────────
- ; The following routine hooks in the interrupt routine and sets up
- ;the data format and communications parameters
- ────────────────────────────────────────────────────────────────────
- PROC SetUpComPort NEAR
- pusha
- push ds es
- mov ax,cs
- mov ds,ax
-
- mov si,offset MSG_SetUp
- call PrintZ
-
- mov al,ComInt
- mov ah,35h
- int 21h
- mov [WORD LOW OldComInt],bx
- mov [WORD HIGH OldComInt],es
-
- mov al,ComInt
- mov dx,offset IntHandler ;ds:dx = new int vector
- mov ah,25h
- int 21h
-
- cli
- mov dx,ComAddr+3 ;point to Line Control register
- mov al,DF_N81
- out dx,al
- inc dx ;point to modem control register
- mov al,00001011b ;set it for interrupts
- out dx,al
-
- in al,21h
- and al,11100111b ;enable both IRQ's
- out 21h,al
-
- mov dx,ComAddr+1
- mov al,00000001b ;turn on int's
- out dx,al
- sti
-
- call SetBaudRate
-
- pop es ds
- popa
- ret
- ENDP
-
- ────────────────────────────────────────────────────────────────────
- ; This one disables the com port and turns off the interrupt
- ────────────────────────────────────────────────────────────────────
- PROC TurnOffComPort NEAR
- pusha
-
- mov dx,ComAddr+1
- mov al,0 ;disable interrupts
- out dx,al
-
- in al,21h
- or al,00011000b ;disable com interrupts
- out 21h,al
-
- push ds
- mov dx,[WORD LOW OldComInt]
- mov ds,[WORD HIGH OldComInt]
- mov al,ComInt
- mov ah,25h
- int 21h
- pop ds
-
- popa
- ret
- ENDP
- ────────────────────────────────────────────────────────────────────
- ; Checks the input buffer and displays everything there
- ────────────────────────────────────────────────────────────────────
- PROC DisplayBuffer NEAR
- pusha
- push es
-
- mov si,[cs:Tail]
- cmp si,[cs:Head]
- je @@NoInput
-
- mov es,[cs:BuffSeg]
- cld
- @@PrintLoop:
- mov dl,[es:si]
- inc si
- mov ah,2
- int 21h
- cmp si,BuffSize
- jne @@NotAtEnd
- xor si,si
-
- @@NotAtEnd:
- cmp si,[cs:Head]
- jne @@PrintLoop
- mov [cs:Tail],si
-
- @@NoInput:
- pop es
- popa
- ret
- ENDP
- ────────────────────────────────────────────────────────────────────
- ; Sends a character across the serial line
- ;
- ; IN: AL = Char
- ;OUT: CF = 1 if timeout occurred
- ────────────────────────────────────────────────────────────────────
- PROC SendChar NEAR
- pusha
- push ax
- xor ah,ah
- int 1ah
- mov [cs:SendCount],dx
-
- @@Xloop1:
- mov dx,ComAddr+5
- in al,dx
- test al,00100000b ;we ready to send?
- jnz @@XLoop2
-
- mov bx,[cs:SendCount]
- mov ax,NormWait
- call CheckTime
- jnc @@XLoop1
- pop ax
- jmp short @@XBad
-
- @@XLoop2:
- pop ax
- mov dx,ComAddr
- out dx,al
-
- clc
- jmp short @@Exit
-
- @@XBad:
- stc
- @@Exit:
- popa
- ret
- ENDP
- ────────────────────────────────────────────────────────────────────
- ; Routine to check if time has elapsed
- ;
- ; IN: BX = original ticks (for timeout)
- ; AX = time to wait
- ;
- ;OUT: CF = 1 if time expired
- ────────────────────────────────────────────────────────────────────
- PROC CheckTime NEAR
- pusha
- mov [cs:CTMax],ax
- mov ah,0
- int 1ah
- cmp bx,dx
- jg short @@Time1 ;check for wrap around
-
- sub dx,bx
- jmp short @@Time2
-
- @@Time1:
- mov ax,0ffffh
- sub ax,bx
- add dx,ax
-
- @@Time2:
- cmp dx,[cs:CtMax]
- ja short @@TimeOut
- clc
- jmp short @@Exit
-
- @@TimeOut:
- stc
- @@Exit:
- popa
- ret
- ENDP
- ────────────────────────────────────────────────────────────────────
- ; sets BAUD rate
- ────────────────────────────────────────────────────────────────────
- PROC SetBaudRate NEAR
- push ax dx
-
- mov dx,ComAddr+3
- in al,dx
- or al,10000000b
- out dx,al
-
- sub dl,2
- mov al,BRDMSB ;set the baud rates
- out dx,al
-
- dec dl
- mov al,BRDLSB
- out dx,al
-
- add dl,3
- in al,dx
- and al,01111111b
- out dx,al
-
- pop dx ax
- ret
- ENDP
-
- ────────────────────────────────────────────────────────────────────
- ; The following routine prints the ASCIIZ string pointed to by DS:SI
- ────────────────────────────────────────────────────────────────────
- PROC PrintZ NEAR
- push ax dx si
-
- mov ah,2
- @@PLoop:
- mov dl,[si]
- inc si
- or dl,dl
- je short @@Done
- int 21h
- jmp short @@PLoop
-
- @@Done:
- pop si dx ax
- ret
- ENDP
-
- ────────────────────────────────────────────────────────────────────
- ; Interrupt handler - process byte coming in on serial channel (COM)
- ────────────────────────────────────────────────────────────────────
- PROC IntHandler FAR
- push ax dx ds es di
-
- mov dx,ComAddr+4 ;point to modem control register
- in al,dx
- and al,11111101b ;turn off RTS
- out dx,al
-
- mov ax,cs
- mov ds,ax
- mov es,[BuffSeg]
- mov di,[Head]
- cld
-
- @@Recieve:
- mov dx,ComAddr
- in al,dx
- stosb
- cmp di,BuffSize
- jne @@NoWrap
- xor di,di
-
- @@NoWrap:
- mov [Head],di
-
- mov dx,Comaddr+2 ;is another byte ready??
- in al,dx
- test al,1
- jz @@Recieve
-
- mov al,20h
- out 20h,al
-
- mov dx,Comaddr+4 ;turn RTS back on
- in al,dx
- or al,00000010b
- out dx,al
-
- pop di es ds dx ax
- iret
- ENDP
- ────────────────────────────────────────────────────────────────────────────
- START:
- mov bx,ss
- mov ax,es
- sub bx,ax
- mov ax,sp
- add ax,15
- shr ax,4
- add bx,ax
- mov ah,4ah
- int 21h ;shrink down to minimum
-
- mov ax,cs
- mov ds,ax
-
- mov ah,48h
- mov bx,BuffSize/16
- int 21h
- jnc @@MemOK
-
- mov si,offset MSG_NoMem
- call PrintZ
- jmp @@AllDone
-
- @@MemOk:
- mov [BuffSeg],ax
- call SetUpComPort
-
- mov si,offset MSG_Exit
- call PrintZ
-
- @@MainLoop:
- mov ah,11h
- int 16h
- jz @@NoKey
-
- mov ah,10h
- int 16h
- cmp ah,134 ;f12 key?
- je @@AllDone
-
- cmp ah,133 ;f11 key? (toggle local echo)
- jne @@Notoggle
- xor [LocalEcho],1
-
- @@Notoggle:
- cmp [LocalEcho],0 ;is local echo on?
- je @@noEcho
-
- push ax
- mov ah,2
- mov dl,al
- int 21h
- pop ax
-
- @@noEcho:
- call SendChar
- jnc @@NoKey
-
- mov si,offset MSG_TimeOut
- call PrintZ
-
- @@NoKey:
- call DisplayBuffer
- jmp @@MainLoop
-
- @@AllDone:
- call TurnOffComPort
- mov es,[Buffseg]
- mov ah,49h
- int 21h
-
- mov ax,4c00h
- int 21h
- END Start
-
-